Skip to content

gio: change write_all/read_all error return type to carry partial count#1981

Open
mvanhorn wants to merge 1 commit into
gtk-rs:mainfrom
mvanhorn:fix/1942-write-all-error-return-type
Open

gio: change write_all/read_all error return type to carry partial count#1981
mvanhorn wants to merge 1 commit into
gtk-rs:mainfrom
mvanhorn:fix/1942-write-all-error-return-type

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Jun 8, 2026

Copy link
Copy Markdown

Summary

Changes the return type of OutputStream::write_all_async/write_all_future and the symmetric InputStream::read_all_async/read_all_future/read_all from Result<(B, usize, Option<glib::Error>), (B, glib::Error)> to Result<(B, usize), (B, usize, glib::Error)>, so callers no longer inspect an inner Option on the Ok path and the error path carries the partial byte count.

Why this matters

The old Ok-with-Some(error) shape forced every caller to check the inner Option even on success, which is confusing and easy to get wrong (#1942). @sdroege agreed the design is wrong and stated the preferred variant Result<(B, usize), (B, usize, glib::Error)>, which also surfaces the partial count on failure. Each async trampoline now builds Ok((buffer, bytes_written)) when no error occurred and Err((buffer, bytes_written, ...)) otherwise, dropping the prior three-state branch. The *_future wrappers mirror the new callback type and the sync read_all surfaces the error directly.

This is a breaking API change, appropriate for the in-progress 0.23.0-alpha cycle.

Testing

  • Added cancellation tests asserting the error path carries the partial byte count for both read_all and write_all.

Closes #1942

@sdroege

sdroege commented Jun 8, 2026

Copy link
Copy Markdown
Member

Test failures need some fixes.

@sdroege

sdroege commented Jun 29, 2026

Copy link
Copy Markdown
Member

@mvanhorn Do you want to update this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

write_all: Return Err if an error occurs

2 participants